package com.base.service.impl;

import java.util.List;

import com.base.bean.Agentbase;
import com.base.service.AgentbaseService;
import com.common.util.AbstractManager;
import com.common.util.PagerModel;

public class AgentbaseServiceImpl extends AbstractManager implements
		AgentbaseService {

	public void addAgentbase(Agentbase agentbase) {
		String hql = "select nvl(max(agentno),0) from Agentbase";
		
		long agentno = 0l;
		agentno = (Long) this.getHibernateTemplate().find(hql).get(0);
		agentno += 1l;
		
		agentbase.setAgentno(agentno);
		this.getHibernateTemplate().save(agentbase);
	}

	public Agentbase findAgentbase(long agentno) {
		return (Agentbase) this.getHibernateTemplate().load(Agentbase.class, agentno);
	}

	public PagerModel findAgentbaseForPager() {
		String hql = "from Agentbase order by agentno";
		return searchPaginated(hql);
	}

	@SuppressWarnings("unchecked")
	public List<Agentbase> findAllAgentbase() {
		String hql = "from Agentbase order by agentno";
		return this.getHibernateTemplate().find(hql);
	}

	public void removeAgentbase(long agentno) {
		Agentbase agentbase = null;
		agentbase = (Agentbase) this.getHibernateTemplate().load(Agentbase.class, agentno);
		if(agentbase != null) 
			this.getHibernateTemplate().delete(agentbase);
	}

	public void updateAgentbase(Agentbase agentbase) {
		this.getHibernateTemplate().update(agentbase);
	}

}
